import { observable, action } from "mobx"
import { StoreModule } from "@/utils/mobx-store"
import { get } from "@/utils/axios"

class ModuleList extends StoreModule {
    @observable
    state = {
        list: []
    }

    @action
    getListMobx = async () => {
        console.log("mobx action 被触发")
        try {
            console.log("发送get请求 (mobx)")
            const url = "https://easy-mock.com/mock/5cb31c49bd0927702544e6a8/test/news#!method=get"
            const res = await get(url)
            if (res.success) {
                console.log("数据请求成功, 并更新state (mobx)")
                this.setState({ list: res.data })
            }
        } catch (err) {
            console.error("get list error", err)
        }
    }
}

export default ModuleList
